<html>
<head><meta charset="utf-8"><title>How do I set non-feature cfgs? · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html">How do I set non-feature cfgs?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="231159234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20do%20I%20set%20non-feature%20cfgs%3F/near/231159234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html#231159234">(Mar 20 2021 at 17:28)</a>:</h4>
<p>I want to pass <code>--cfg spec</code> when checking my code. I found <code>cargo.features</code>, but that appears to force the usage of "feature".</p>



<a name="231159694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20do%20I%20set%20non-feature%20cfgs%3F/near/231159694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html#231159694">(Mar 20 2021 at 17:35)</a>:</h4>
<p>I think currently the only way to do this is to set it from a build script</p>



<a name="231159965"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20do%20I%20set%20non-feature%20cfgs%3F/near/231159965" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html#231159965">(Mar 20 2021 at 17:40)</a>:</h4>
<p>does RA allow passing arbitrary rustflags?</p>



<a name="231160029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20do%20I%20set%20non-feature%20cfgs%3F/near/231160029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html#231160029">(Mar 20 2021 at 17:41)</a>:</h4>
<p><code>RUSTFLAGS</code> is passed through, but we ignore it</p>



<a name="231161352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20do%20I%20set%20non-feature%20cfgs%3F/near/231161352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html#231161352">(Mar 20 2021 at 18:02)</a>:</h4>
<p>Unfortunate. It looks like it _was_ supported at some point? <a href="https://github.com/rust-analyzer/rust-analyzer/issues/1073">https://github.com/rust-analyzer/rust-analyzer/issues/1073</a></p>



<a name="231161391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20do%20I%20set%20non-feature%20cfgs%3F/near/231161391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html#231161391">(Mar 20 2021 at 18:03)</a>:</h4>
<p>Oh, maybe that's literally also just features</p>



<a name="231161527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20do%20I%20set%20non-feature%20cfgs%3F/near/231161527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html#231161527">(Mar 20 2021 at 18:05)</a>:</h4>
<p>Nothing was removed here, that issue was closed when basic support for handling <code>#[cfg]</code> landed</p>



<a name="231161828"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20do%20I%20set%20non-feature%20cfgs%3F/near/231161828" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html#231161828">(Mar 20 2021 at 18:10)</a>:</h4>
<p>Should I open an issue for supporting additional <code>cfg</code>?</p>



<a name="231161844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20do%20I%20set%20non-feature%20cfgs%3F/near/231161844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html#231161844">(Mar 20 2021 at 18:11)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/issues/5421">https://github.com/rust-analyzer/rust-analyzer/issues/5421</a></p>



<a name="231161929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20do%20I%20set%20non-feature%20cfgs%3F/near/231161929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html#231161929">(Mar 20 2021 at 18:12)</a>:</h4>
<p>I did see that there's an option for <code>cfg</code> when not using Cargo — <a href="https://rust-analyzer.github.io/manual.html#non-cargo-based-projects">https://rust-analyzer.github.io/manual.html#non-cargo-based-projects</a></p>



<a name="231347142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20do%20I%20set%20non-feature%20cfgs%3F/near/231347142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html#231347142">(Mar 22 2021 at 17:02)</a>:</h4>
<p>Should be perhaps pares RUSTFLAGS?</p>



<a name="231347255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20do%20I%20set%20non-feature%20cfgs%3F/near/231347255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html#231347255">(Mar 22 2021 at 17:03)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> what do you use to set this for cargo? RUSTFLAGS or something else?</p>



<a name="231347487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20do%20I%20set%20non-feature%20cfgs%3F/near/231347487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html#231347487">(Mar 22 2021 at 17:04)</a>:</h4>
<p>You can use <code>rustc --print cfg $RUSTFLAGS</code> to get the list of all enabled cfgs.</p>



<a name="231347692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20do%20I%20set%20non-feature%20cfgs%3F/near/231347692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html#231347692">(Mar 22 2021 at 17:05)</a>:</h4>
<p>wow, that's <strong>nice</strong>, that means that the impl is trivial, as we are already running <code>--print cfg</code></p>



<a name="231627607"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20do%20I%20set%20non-feature%20cfgs%3F/near/231627607" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html#231627607">(Mar 24 2021 at 12:53)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133169">matklad</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/How.20do.20I.20set.20non-feature.20cfgs.3F/near/231347255">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="116155">Jake Goulding</span> what do you use to set this for cargo? RUSTFLAGS or something else?</p>
</blockquote>
<p>I am running:</p>
<div class="codehilite"><pre><span></span><code>CARGO_BUILD_PIPELINING=false cargo rustc -- --crate-type=bin --cfg=spec
</code></pre></div>



<a name="231627661"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20do%20I%20set%20non-feature%20cfgs%3F/near/231627661" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html#231627661">(Mar 24 2021 at 12:53)</a>:</h4>
<p>(sorry for long delays; been in a <em>lot</em> of training <span aria-label="wink" class="emoji emoji-1f609" role="img" title="wink">:wink:</span>)</p>



<a name="231628598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20do%20I%20set%20non-feature%20cfgs%3F/near/231628598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html#231628598">(Mar 24 2021 at 12:59)</a>:</h4>
<p>Hm, that's tricky -- while <code>RUSFLAGS</code> are global, config via <code>rustc</code> I think applies only to one target. Yup:</p>
<blockquote>
<p>The specified args will all be passed to the final compiler invocation, not any of the dependencies. </p>
</blockquote>
<p>So the config we want here would be a map from (package, target) pairs to additional cfg. It shouldn't be that hard to implement, but would be quite annoing, especially because there's no clean way to identifiy a package/target pair (cargo identifies them implicitly, via --lib, --bin, etc args)</p>



<a name="231794088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20do%20I%20set%20non-feature%20cfgs%3F/near/231794088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html#231794088">(Mar 25 2021 at 12:50)</a>:</h4>
<p>For my <em>particular</em> case, the cfg could go to every crate. It’s the exact same concept as cfg(test).</p>



<a name="231794218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/How%20do%20I%20set%20non-feature%20cfgs%3F/near/231794218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/How.20do.20I.20set.20non-feature.20cfgs.3F.html#231794218">(Mar 25 2021 at 12:51)</a>:</h4>
<p>People would want it to effectively always be on in their editor if they were using this.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>